package com.example.redcultural;

import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.youth.banner.Banner;

import java.util.ArrayList;
import java.util.List;
public class story extends Fragment {
    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    String[] bookName;
    ArrayAdapter arrayAdapter;
    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;
    private OnFragmentInteractionListener mListener;
    private LinearLayout ph,rm,jd;
private ListView book_list;
    public story() {
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param param1 Parameter 1.
     * @param param2 Parameter 2.
     * @return A new instance of fragment story.
     */
    // TODO: Rename and change types and number of parameters
    public static story newInstance(String param1, String param2) {
        story fragment = new story();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragment_story,container,false);
        // Inflate the layout for this fragment
        ph=view.findViewById(R.id.ph);
        rm=view.findViewById(R.id.rm);
        jd=view.findViewById(R.id.jd);
        book_list=view.findViewById(R.id.book_list);
        bookName= new String[]{"三湾改编的故事",
                "遂川分兵的故事",
                "草林圩群众大会的故事",
                "曲艺表演登上大雅之堂的故事",
                "标语漫画遍布根据地的故事",
                "红军标语的故事",
                "根据地的宣传画漫画的内容",
                "工农革命军军官教导队的开办",
                "根据地的巩固，文化教育不断兴起",
                "根据地的红军教育",
                "根据地的群众教育",
                "根据地的党员教育",
                "根据地的壮大,红色革命文化普遍发展",
                "客家山歌绚丽多彩",
                "地方戏曲新发展的故事",
                "楹联文告彪炳青史"};
        ph.setBackgroundResource(R.drawable.shape_bj);
        List<String> images = new ArrayList<>();
        images.add("https://gss2.bdstatic.com/-fo3dSag_xI4khGkpoWK1HF6hhy/baike/c0%3Dbaike80%2C5%2C5%2C80%2C26/sign=e1622ab30d0828387c00d446d9f0c264/37d12f2eb9389b5089df61fe8f35e5dde7116e7e.jpg");
        images.add("https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=3047121918,760524430&fm=26&gp=0.jpg");
        images.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1559872834&di=32f0b35ff786d9156180bfc8addb3d5c&imgtype=jpg&er=1&src=http%3A%2F%2Fp4.ssl.cdn.btime.com%2Ft01bd80b9441e37db7b.jpg%3Fsize%3D605x375");
        images.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1559278195348&di=cccaf2737304d1a42a3aee7d75cc3d64&imgtype=0&src=http%3A%2F%2Fcpc.people.com.cn%2Fmediafile%2F200610%2F10%2FP200610101120127123100682.jpg");
        //设置轮播
        Banner banner = view.findViewById(R.id.banner);
        banner.setImages(images).setImageLoader(new GlideImageLoader()).start();
        arrayAdapter=new ArrayAdapter<>(getActivity(),R.layout.support_simple_spinner_dropdown_item,bookName);
        ph.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                bookName= new String[]{"三湾改编的故事",
                        "遂川分兵的故事",
                        "草林圩群众大会的故事",
                        "曲艺表演登上大雅之堂的故事",
                        "标语漫画遍布根据地的故事",
                        "红军标语的故事",
                        "根据地的宣传画漫画的内容",
                        "工农革命军军官教导队的开办",
                        "根据地的巩固，文化教育不断兴起",
                        "根据地的红军教育",
                        "根据地的群众教育",
                        "根据地的党员教育",
                        "根据地的壮大,红色革命文化普遍发展",
                        "客家山歌绚丽多彩",
                        "地方戏曲新发展的故事",
                        "楹联文告彪炳青史"};
                arrayAdapter=new ArrayAdapter<>(getActivity(),R.layout.support_simple_spinner_dropdown_item,bookName);
                ph.setBackgroundResource(R.drawable.shape_bj);
                rm.setBackgroundColor(Color.WHITE);
                jd.setBackgroundColor(Color.WHITE);
                book_list.setAdapter(arrayAdapter);
            }
        });
        rm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                bookName= new String[]{
                        "文化封锁的故事",
                        "龙源口大捷的故事”",
                        "黄洋界保卫线的故事”",
                        "诗歌体布告威震湘赣的故事",
                        "湘赣边界特委第四次执委扩的故事",
                        "红色革命文化传播赣南闽西",
                        "古田会议的故事"};
                arrayAdapter=new ArrayAdapter<>(getActivity(),R.layout.support_simple_spinner_dropdown_item,bookName);
                rm.setBackgroundResource(R.drawable.shape_bj);
                ph.setBackgroundColor(Color.WHITE);
                jd.setBackgroundColor(Color.WHITE);
                book_list.setAdapter(arrayAdapter);
            }
        });
        jd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                bookName= new String[]{"红色革命文化是中国先进文化的重要组成部分",
                        "红色革命文化是中国革命战争文化的优秀结晶",
                        "红色革命文化闪耀着中华民族革命精神的光辉",
                        "加强社会主义精神文明建设,需要进一步弘扬红色革命文化",
                        "“加强对青少年的理想道德教育需要进一步弘扬红色革命文化”",
                        "推进社会主义新农村建设,需要进一步弘扬红色革命文化"};
                arrayAdapter=new ArrayAdapter<>(getActivity(),R.layout.support_simple_spinner_dropdown_item,bookName);
                jd.setBackgroundResource(R.drawable.shape_bj);
                rm.setBackgroundColor(Color.WHITE);
                ph.setBackgroundColor(Color.WHITE);
                book_list.setAdapter(arrayAdapter);
            }
        });
        book_list.setAdapter(arrayAdapter);
        book_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if(bookName.length==7)
                {
                    position=position+16;
                }else if(bookName.length==6)
                {
                 position=position+16+7;
                }
                Intent intent=new Intent(getActivity(),itemStory.class);
                intent.putExtra("id",position);
                startActivity(intent);
            }
        });
        return view;
    }

    // TODO: Rename method, update argument and hook method into UI event
    public void onButtonPressed(Uri uri) {
        if (mListener != null) {
            mListener.onFragmentInteraction(uri);
        }
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);

    }
    @Override
    public void onDetach() {
        super.onDetach();
        mListener = null;
    }

    /**
     * This interface must be implemented by activities that contain this
     * fragment to allow an interaction in this fragment to be communicated
     * to the activity and potentially other fragments contained in that
     * activity.
     * <p>
     * See the Android Training lesson <a href=
     * "http://developer.android.com/training/basics/fragments/communicating.html"
     * >Communicating with Other Fragments</a> for more information.
     */
    public interface OnFragmentInteractionListener {
        // TODO: Update argument type and name
        void onFragmentInteraction(Uri uri);
    }

}
